package com.sky.controller.user;

import com.sky.constant.StatusConstant;
import com.sky.pojo.Category;
import com.sky.pojo.Setmeal;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import com.sky.service.admin.DishService;
import com.sky.service.admin.SetMealService;
import com.sky.service.user.UserDishService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("")
@Slf4j
@Api(value = "菜品管理")
public class UserDishController {
    @Autowired
    private UserDishService dishService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private DishService dishService1;
    @Autowired
    private SetMealService setMealService;
    @GetMapping("/user/dish/list")
    @ApiOperation("商品分类id查询")
    public Result<List> selectDishByCategoryId(Integer categoryId){
        List<DishVO> list = dishService1.selectDishByCategoryId(categoryId);

        return Result.success(list);
    }

    @GetMapping("/user/category/list")
    @ApiOperation("查询菜品的分类(侧边栏)")
    public Result<List> selectAllCategory(Integer type){
        //构造 redis中的 key  根据dish_分类id 已改完
        List<Category> list = categoryService.selectAllCategoryFromCache(type);
        return Result.success(list);
    }

    @GetMapping("/user/setmeal/list")
    @ApiOperation("根据categoryID 查询套餐 ")
    public Result<List> selectSetmealByCategoryId(Long categoryId){
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(categoryId);
        setmeal.setStatus(StatusConstant.ENABLE);
        List<SetmealVO> list = dishService.selectAllSetmeal(setmeal);
        return Result.success(list);
    }



    @GetMapping("/user/setmeal/dish/{setmealId}")
    @ApiOperation("查询套餐的内容")
    public Result<List> selectDishFromSetmeal(@PathVariable Long setmealId){
        List<DishItemVO> list = dishService.selectDishFromSetmeal(setmealId);
        return Result.success(list);
    }

}
